package com.espirit.finance.core;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.espirit.EntityMapping;
import com.espirit.eap.annotation.Dict;
import com.googlecode.cswish.model.Saas;

@MappedSuperclass
public class Voucher extends EntityMapping implements Serializable, Saas{
	private static final long serialVersionUID = 1154171500047794720L;

	private Integer sid;
	public Integer getSid() {
		return sid;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}
	
	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	
	public Date getVoucherOn() {
		return voucherOn;
	}
	public void setVoucherOn(Date voucherOn) {
		this.voucherOn = voucherOn;
	}

	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	@Dict(type=Acct.DC)
	public Integer getDc() {
		return dc;
	}
	public void setDc(Integer dc) {
		this.dc = dc;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	public AcctItem getAcctItem() {
		return acctItem;
	}
	public void setAcctItem(AcctItem accountBookStandard) {
		this.acctItem = accountBookStandard;
	}
	
	@Transient
	public TicketAware getTicketAware() {
		return ticketAware;
	}
	public void setTicketAware(TicketAware ticketAware) {
		this.ticketAware = ticketAware;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	public AcctTerm getAcctTerm() {
		return acctTerm;
	}
	public void setAcctTerm(AcctTerm acctTerm) {
		this.acctTerm = acctTerm;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	public Acct getAcct() {
		return acct;
	}
	public void setAcct(Acct acct) {
		this.acct = acct;
	}
	
	@Transient
	public BigDecimal getDcAmount(){
		if (amount == null) return null;
		if (dc == null) return amount;
		return amount.multiply(BigDecimal.valueOf(dc));
	}

	private Date voucherOn;
	private Date createdOn;
	private AcctItem acctItem;
	private BigDecimal amount;
	private Integer dc ;
	private AcctTerm acctTerm;
	
	private TicketAware ticketAware;
	private Acct acct;
}
